import { ILoadMapTypeAll } from '@/common';
import { ManageCommonAPI } from '@/pages/type';
import { getSelectDataMapList, getTenantID, getUserDepID } from '@/utils';
import { useEffect, useMemo } from 'react';
import { getFlowOrgTreeByOrgIDService } from '@/services/BaseLayout';

/** 资产/材料列表搜索 */
const getMaterialSearchList = (loadInfo: Record<string, any>, type, queryType, belongID): ManageCommonAPI.ISearchList => {
  /** 物资分类 */
  const materialTypeMapList = getSelectDataMapList(loadInfo?.loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`], 'name', 'id', true);

  /**
   * 物资归属类型
   * @functionContent 根据表单货物所属部门,是否等于当前登陆人部门
   * 等于：展示三种 | 不等于：展示一种
   * */
  const sharingTypeMemo = useMemo(() => {
    if (belongID === getUserDepID()) {
      return [
        {
          name: '部门专用',
          value: '0',
        },
        {
          name: '单位共有',
          value: '1',
        },
        {
          name: '个人入库',
          value: '2',
        },
      ];
    } else {
      return [
        {
          name: '单位共有',
          value: '1',
        },
      ];
    }
  }, [belongID]);

  return [
    {
      name: 'assetCode',
      placeholder: '资产编号',
      label: '资产编号',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetName',
      placeholder: type == 1 ? '资产名称' : '材料名称',
      label: type == 1 ? '资产名称' : '材料名称',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetClass',
      placeholder: type == 1 ? '资产分类' : '材料分类',
      label: type == 1 ? '资产分类' : '材料分类',
      componentType: 'TreeSelect',
      dataSource: materialTypeMapList,
      showSearch: true,
      treeNodeFilterProp: 'name',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      fieldNames: {
        label: 'name',
        value: 'id',
        children: 'children',
      },
    },
    {
      name: 'brandType',
      placeholder: '品牌',
      label: '品牌',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'paramsInfo',
      placeholder: '规格型号',
      label: '规格型号',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'sharing',
      placeholder: '物资归属类型',
      label: '物资归属类型',
      ishidden: queryType == '1' || queryType == '3' ? false : true,
      componentType: 'Select',
      dataSource: sharingTypeMemo,
      // allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
  ];
};

export { getMaterialSearchList };

/** 获取组织机构树接口 */
// const { getFlowOrgTreeRun, getFlowOrgTreeLoading, getFlowOrgList } = getFlowOrgTreeByOrgIDService();

// useEffect(() => {
//   /** 初始化请求组织机构 */
//   let payload = {
//     params: '0',
//     flowType: '0',
//   };
//   getFlowOrgTreeRun(payload);
// }, []);

// {
//   name: 'createDepartmentID',
//   placeholder: '货物所属部门',
//   label: '货物所属部门',
//   componentType: 'TreeSelect',
//   dataSource: handleNotPostion(getFlowOrgList),
//   allowClear: true,
//   showSearch: true,
//   treeNodeFilterProp: 'title',
//   md: 4,
//   sm: 36,
//   whetherSenior: false,
//   fieldNames: {
//     label: 'title',
//     value: 'id',
//     children: 'children',
//   },
// },
